package iss.java;

import iss.java.list.MyList;
import iss.java.list.Node;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import iss.java.list.MyList;
import iss.java.list.Node;

/**
 * Created by wenke on 2016/9/16.
 * NOTE: This is an example of how to iterate MyList.
 */
public class Main {
    public static void main(String[] args) {
        MyList list = new MyList();
        Lock lock = new ReentrantLock();
        list.insert(list.getHead(), 5, lock);
        list.insert(list.getHead(), 4, lock);
        list.insert(list.getHead(), 3, lock);
        list.insert(list.getHead(), 2, lock);
        list.insert(list.getHead(), 1, lock);

        // Traverse from head to tail, exclude head and tail
        for (Node n = list.getHead().getNext(); n!=list.getTail(); n=n.getNext()) {
            System.out.printf("%d ", n.getData());
        }
        System.out.println();

        list.remove(list,list.getHead().getNext(),lock);
        // Traverse from tail to head, exclude tail and head.
        for (Node n = list.getTail().getPrev(); n!=list.getHead(); n=n.getPrev()) {
            System.out.printf("%d ", n.getData());
        }
        System.out.println();
    }
}
